<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Symbol的特性</title>
</head>
<body>
    <script>
        let symbol = Symbol('这是一个Symbol类型');

        let hd = {
            name : "李四",
            [symbol] : "后盾人很不错"
        };

        // 一般情况下，symbol不可以使用for...of...和for...in...进行遍历
        for (const key in hd) {
            console.log(key);//只能遍历出name
        }

        for (const value of Object.keys(hd)) {
            console.log(value);//只能遍历出name
        }

        for (const value of Object.getOwnPropertySymbols(hd)) {
            console.log(value);//只能遍历出symbol类型
        }

        for (const value of Reflect.ownKeys(hd)) {
            console.log(value);//既能遍历出symbol类型,又能遍历出普通类型
        }



        // 例：将一些属性私有化，保护起来
        let site = Symbol("这是一个站点");
        class User{
            constructor(name){
                this.name = name;
                this[site] = "后盾人";
            };
            getName(){
                return `${this.name} ${this[site]}`;
            }
        }

        let lisi = new User("李四");
        console.log(lisi.getName());
    </script>
</body>
</html>